package com.app.service.Impl;

import com.app.mapper.NoticeMapper;
import com.app.model.NoticeModel;
import com.app.service.NoticeService;
import com.app.util.StringTool;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

@Service
@Primary
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    NoticeMapper noticeMapper;


    @Override
    public Page<NoticeModel> getPageByModel(NoticeModel model) {
        QueryWrapper<NoticeModel> queryWrapper = new QueryWrapper<>();
        if(StringTool.isNotEmpty(model.getKeyWord())){
            queryWrapper.like("title",model.getKeyWord());
        }
        queryWrapper.orderByDesc("id");
        Page<NoticeModel> pages = new Page<>();
        pages.setCurrent(model.getPage());
        pages.setSize(model.getLimit());
        Page<NoticeModel> page = noticeMapper.selectPage(pages,queryWrapper);
        return page;
    }

    @Override
    public int insert(NoticeModel model) {

        return noticeMapper.insert(model);
    }

    @Override
    public void update(NoticeModel model) {
        noticeMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        noticeMapper.deleteById(id);
    }

    @Override
    public NoticeModel getModelBtId(Integer id) {
        return noticeMapper.selectById(id);
    }
}
